package com.baohua.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baohua.dao.AutoCompleteDao;
import com.baohua.model.Member;
import com.baohua.service.AutoCompleteService;

@Service("autoCompleteService")
public class AutoCompleteServiceImpl implements AutoCompleteService {
	
	private AutoCompleteDao autoCompleteDao;

	public AutoCompleteDao getAutoCompleteDao() {
		return autoCompleteDao;
	}

	@Resource(name="autoCompleteDao")
	public void setAutoCompleteDao(AutoCompleteDao autoCompleteDao) {
		this.autoCompleteDao = autoCompleteDao;
	}


	@Override
	public List<String> getAllMemberNo(String query) {
		
		String memberNo=null;
		String memberName=null;
		String mobile=null;
		
		query = query.toLowerCase();
		
		List<String> list = new ArrayList<String>();
		
		List<String> memberNos = new ArrayList<String>();
		memberNos = autoCompleteDao.getAllMemberNo();
		List<String> memberNames = new ArrayList<String>();
		memberNames = autoCompleteDao.getAllMemberName();		
		List<String> mobiles = new ArrayList<String>();
		mobiles = autoCompleteDao.getAllMobile();
		
        for(int i=0; i < memberNos.size(); i++) {
        	
        	memberNo = memberNos.get(i).toLowerCase();
        	memberName = memberNames.get(i).toLowerCase();
        	mobile = mobiles.get(i).toLowerCase();
        	
            if(memberNo.startsWith(query)||memberName.contains(query)||mobile.contains(query)) {
            	list.add(memberNos.get(i)+","+memberNames.get(i)+","+mobiles.get(i));          	
            }          
        }
        System.out.println(list.get(1));
		return list;
	}

	
	
	
	/**
	 * 通过memberNo获取member
	 * 
	 * */
	@Override
	public String getMemberName(String memberNo) {
		Member member = autoCompleteDao.getMemberByMemberNo(memberNo);
		return member.getMemberName();
	}
}
